package main

import (
	"fmt"
)

func main() {
	//map：键值对的组合，key->val
	//map也是变量的类型
	var scores map[string]uint
	//map如果只定义是一个空map，nil代表Go语言的空
	scores = make(map[string]uint)

	scores["yekai"] = 99
	scores["fuhongxue"] = 89

	fmt.Println(scores)
	fmt.Println("yekai's score is ", scores["yekai"])
	//scores["luxiaojia"]为0有2个可能，一个是此人不存在，另一个是此人存在，但结果为0
	fmt.Println("luxiaojia's score is ", scores["luxiaojia"])
	//可以使用指示器读取map
	score, ok := scores["yekai"]
	fmt.Println(score, ok)
	//如何遍历map，问题在于不能像数组那样，内存单元不连续，数量也不确定
	fmt.Println(len(scores))
	//range关键字可以遍历map，数组，切片
	for key, val := range scores {
		fmt.Printf("%s's score is %d\n", key, val)
	}
	a1 := [5]int{1, 2, 3, 4, 5}
	for k, v := range a1 {
		fmt.Printf("a1[%d] = %d\n", k, v)
	}
}
